<%@ page contentType="text/html;charset=UTF-8" language="java" %> <%@ page isELIgnored="false" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";
%>

<div id="page-content">
    <div class="row">

        <div class="col-lg-12">
            <div class="panel">
                <div class="panel-heading">
                    <h3 class="panel-title">公告通知</h3>
                </div>
                <div class="panel-body">
                    <div class="form-inline">
                        <div class="row">
                            <div class="col-sm-12 table-toolbar-left">
                                <btn id="btn_add_notice" class="btn btn-primary btn-sm" ${isCreate}>
                                    <i class="ti-plus"> </i> 新建公告通知
                                </btn>
                            </div>
                        </div>
                    </div>
                    <div class="table-responsive">
                        <table id="notice_running_table"></table>
                        <div id="notice_running_page"></div>
                    </div>
                </div>
            </div>
        </div>

    </div>
</div>

<script>

    $(function(){

        init_grid_notice();

    });

    function init_grid_notice() {

        __init_jqgrid('notice_running_table', 'notice_running_page',
                '<%=path%>/com/notice/list',
                ['','公告类型', '通知主题', '发布部门', '提交日期', '操作', 'id'],
                [
                    {name: 'isTop', index: 'isTop', width: 20, sortable: false, search: false, formatter: isTopFormat},
                    {name: 'name', index: 'name', width: 40, sortable: true, search: true, searchoptions: {sopt: ['cn']}},
                    {name: 'subject', index: 'subject', width: 100, sortable: true, stype: 'text', searchoptions: {sopt: ['cn']}},
                    {name: 'issueDepartment', index: 'issueDepartment', width: 80, sortable: true, search: true, searchoptions: {sopt: ['cn']}},
                    {name: 'dateApply', index: 'dateApply', width: 60, sortable: true, search: true, formatter: dateOnlyFormat, searchoptions: {sopt: ['cn']}},
                    {name: 'act', index: 'act', width: 200, fixed: true, sortable: false, search: false, formatter: actFormat},
                    {name: 'id', index: 'id', width: 100, key: true, hidden: true, hidedlg: true}
                ],
                true,true
        );

    }

    function isTopFormat(cellvalue, options, rowObject){
        if(rowObject.isTop == 1){
            cellvalue = "<button class='btn btn-warning btn-icon btn-circle'><i class='fa fa-envira icon-lg'></i></button>";
        } else {
            cellvalue = "";
        }
        return cellvalue;
    }

    function dateOnlyFormat(cellvalue, options, rowObject){
        return cellvalue.split(" ")[0];
    }

    function actFormat(cellvalue, options, rowObject){
        var id = rowObject.id;
        cellvalue = '<button class="btn btn-white btn-sm" onclick="fn_notice_read(\'' + id + '\');"><i class="fa fa-eye"> </i> 查看</button>';
        var isTop = rowObject.isTop;
        if(isTop == 1){
            cellvalue += '<button class="btn btn-white btn-sm" onclick="fn_notice_cancelTop(\'' + id + '\');"><i class="ti-close"> </i> 取消置顶</button>';
        } else {
            cellvalue += '<button class="btn btn-white btn-sm" onclick="fn_notice_setTop(\'' + id + '\');"><i class="ti-arrow-up"> </i> 置顶</button>';
        }
        return cellvalue;
    }

    function fn_notice_read(id) {
        loadURL('<%=path%>/com/notice/read?keyId='+id, $('#page-content'));
    }

    function fn_notice_cancelTop(id) {
        __confirm_dialog("对话框","确认执行此操作？",function () {
            var url = '<%=path%>/com/notice/cancelTop/'+id;
            __ajax_get(url, null, function(data) {
                __toastr(data);
                if(data.state == 1) {
                    // 刷新
                    $('#notice_running_table').jqGrid().setGridParam({datatype:'json'}).trigger('reloadGrid');
                }
            });
        })
    }

    function fn_notice_setTop(id) {
        __confirm_dialog("对话框","确认执行此操作？",function () {
            var url = '<%=path%>/com/notice/setTop/'+id;
            __ajax_get(url, null, function(data) {
                __toastr(data);
                if(data.state == 1) {
                    // 刷新
                    $('#notice_running_table').jqGrid().setGridParam({datatype:'json'}).trigger('reloadGrid');
                }
            });
        })
    }

    $("#btn_add_notice").click(function(){
        loadURL('<%=path%>/com/notice/input', $('#page-content'));
    });
</script>